home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
komercni software
/
miton
/
SystemMechanic7Pro.exe
/
{app}
/
smhtml.dll
/
1033
/
HTML
/
CHECKBOX.JS
< prev
next >
Wrap
Text File
|
2008-01-24
|
6KB
|
249 lines
var _CHECKBOX_CHECKED = "0";
var _CHECKBOX_UNCHECKED = "1";
var _CHECKBOX_DISABLE_CHECKED = "2";
var _CHECKBOX_DISABLE_UNCHECKED = "3";
var _CHECKBOX_MIX = "4";
var __HIDDEN = "<input type=\"hidden\" id=\"{id}\" value=\"{value}\" />";
var __IMAGE = "<img src=\"{image}\" id=\"{id}\" onmouseover=\"{mouseover}\" onmouseout=\"{mouseout}\" onclick=\"{onclick}{EVENT}\" align=\"absmiddle\" style=\"cursor:hand;\" />";
function CheckBox()
{
this.ID = "";
// if the id is passed as an argument
if( arguments.length == 1 )
this.ID = this.ID = arguments[0];
this.State = _CHECKBOX_UNCHECKED;
this.lblText = new Label();
this.lblText.Text = "";
this.OnClickEvent = "__OnClickCheckBox";
this.OnMouseOver = "__OnMouseOverCheckBox";
this.OnMouseOut = "__OnMouseOutCheckBox";
this.OnClickCustomEvent = "";
this.Render = __RenderCheckBox;
this.SetState = __SetCheckBoxState;
this.GetState = __GetCheckBoxState;
this.Enable = __EnableCheckBox;
this.Check = __CheckCheckBox;
this.IsChecked = __IsCheckedCheckBox;
this.Toggle = __ToggleCheckBox;
this.IsRendered = __CheckBoxIsRendered;
}
function __CheckBoxIsRendered()
{
return Get( "hid_"+ this.ID ) == null ? false : true;
}
function __RenderCheckBox()
{
// replace hidden field's id and value
var hid = __HIDDEN.replace("{id}","hid_"+ this.ID);
hid = hid.replace("{value}",this.State);
// replace image's id, src and onclick event
var image = __IMAGE.replace("{id}","image_"+ this.ID);
image = image.replace("{image}",__GetCheckBoxImage(this.State ) );
image = image.replace("{onclick}", this.OnClickEvent + "('hid_"+ this.ID +"','image_"+this.ID+"');" );
image = image.replace("{mouseover}", this.OnMouseOver + "('hid_"+ this.ID +"','image_"+this.ID+"');" );
image = image.replace("{mouseout}", this.OnMouseOut + "('hid_"+ this.ID +"','image_"+this.ID+"');" );
image = image.replace("{EVENT}",this.OnClickCustomEvent );
this.lblText.ID = "chktext_" + this.ID;
this.lblText.OnClickEvent = this.OnClickEvent;
var text = ((this.lblText.Text == "" )? "": this.lblText.Render());
return image + " " + text + hid;
}
function __SetCheckBoxState( state )
{
var img = Get( "image_" + this.ID );
img.src = __GetCheckBoxImage ( state ); // change image
Get( "hid_"+ this.ID ).value = state; // change hidden value
}
function __GetCheckBoxState()
{
return Get( "hid_"+ this.ID ).value;
}
// value = boolean
function __EnableCheckBox( value )
{
var state = Get( "hid_"+ this.ID ).value; // get current state
var temstate = state;
if( value ) // if enable = true
{
switch( state )
{
case _CHECKBOX_DISABLE_CHECKED:
temstate = _CHECKBOX_CHECKED;
break;
case _CHECKBOX_DISABLE_UNCHECKED:
temstate = _CHECKBOX_UNCHECKED;
break;
}
}else
{
switch( state ) // if enable = false
{
case _CHECKBOX_CHECKED:
temstate = _CHECKBOX_DISABLE_CHECKED;
break;
case _CHECKBOX_UNCHECKED:
temstate = _CHECKBOX_DISABLE_UNCHECKED;
break;
}
}
Get( "hid_"+ this.ID ).value = temstate; // change hiddeb value (state )
Get( "image_"+ this.ID ).src = __GetCheckBoxImage(temstate ); // change image
}
// value = boolean
function __CheckCheckBox( value )
{
var state = Get( "hid_"+ this.ID ).value; // get current state
var temstate = (value == true )? _CHECKBOX_CHECKED : _CHECKBOX_UNCHECKED ;
if( (state == _CHECKBOX_CHECKED) || (state == _CHECKBOX_UNCHECKED) )
{
Get( "hid_"+ this.ID ).value = temstate; // change hiddeb value (state )
Get( "image_"+ this.ID ).src = __GetCheckBoxImage(temstate ); // change image
}
}
function __IsCheckedCheckBox()
{
if( Get( "hid_"+ this.ID ) == null )
return false;
return __GetCheckBoxValue( Get( "hid_"+ this.ID ).value);
}
// toggle the checkbox state
function __ToggleCheckBox()
{
__OnClickCheckBox("hid_"+ this.ID, "image_"+ this.ID );
}
//************************************ helper functions ************************************************************
function __OnClickCheckBox(hidid, imageid)
{
var hid = Get( hidid ).value; // get current state
if ( hid == _CHECKBOX_UNCHECKED )
{
Get( hidid ).value = _CHECKBOX_CHECKED;
Get(imageid ).src = __GetCheckBoxImage( _CHECKBOX_CHECKED );
}
if ( hid == _CHECKBOX_CHECKED )
{
Get( hidid ).value = _CHECKBOX_UNCHECKED;
Get(imageid ).src = __GetCheckBoxImage( _CHECKBOX_UNCHECKED );
}
}
function __OnMouseOverCheckBox(hidid, imageid)
{
var hid = Get( hidid ).value; // get current state
Get(imageid ).src = __GetCheckBoxImage( hid, true );
}
function __OnMouseOutCheckBox(hidid, imageid)
{
var hid = Get( hidid ).value; // get current state
Get(imageid ).src = __GetCheckBoxImage( hid );
}
//return checkbox boolean value, for given state
function __GetCheckBoxValue( state )
{
switch( state )
{
case _CHECKBOX_CHECKED:
case _CHECKBOX_DISABLE_CHECKED:
return true;
break;
case _CHECKBOX_UNCHECKED:
case _CHECKBOX_DISABLE_UNCHECKED:
return false;
break;
}
}
//return image for the given state
//mouseover : bool
function __GetCheckBoxImage( state, mouseover )
{
var m = mouseover || false;
switch( state )
{
case _CHECKBOX_CHECKED:
return m ? "P_check_selectedhover.gif" : "P_check_selected.gif";
break;
case _CHECKBOX_DISABLE_CHECKED:
return "checkbox_checked_disable.JPG";
break;
case _CHECKBOX_MIX:
return m ? "P_check_mixedhover.gif" : "P_check_mixed.gif";
break;
case _CHECKBOX_DISABLE_UNCHECKED:
return "checkbox_unchecked_disable.JPG";
break;
case _CHECKBOX_UNCHECKED:
return m ? "P_check_unselectedhover.gif" : "P_check_unselected.gif";
break;
}
}
//*******************************************************************
function c1()
{
var c = new CheckBox("XXX");
Get("div").innerHTML = c.Render();
}
function c2()
{
var c = new CheckBox("XXX");
c.SetState( _CHECKBOX_MIX );
}
function c3()
{
var c = new CheckBox("XXX");
c.Enable(true);
}
function c4()
{
var c = new CheckBox("XXX");
c.Enable(false);
}